package com.ys.controller.web.finance;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.controller.api.finance.ApiInterTcwPointTransferController;
import com.ys.entity.finance.TcwPointTransfer;
import com.ys.entity.shiro.LoginUser;
import com.ys.service.sys.CommonApiService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.W;

@Controller
@RequestMapping("/web/finance/tcwPointTransfer")
public class WebTcwPointTransferController {
	
	@Autowired
	private CommonApiService<TcwPointTransfer> commonApiService;
	
	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){

		try {
			String bid = commonApiService.getCommonNextBid(ApiInterTcwPointTransferController.MENU_ID);
			
			LoginUser loginUser = ShiroUtils.getLoginUser();
			TcwPointTransfer entity = new TcwPointTransfer()
					.setBid(bid)
					.setUserIdFrom(loginUser.getUserId())
					.setUserNameFrom(loginUser.getUserName());
			
			return commonApiService.toAdd(model, entity, ApiInterTcwPointTransferController.MENU_ID, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 审核
	 */
	@RequiresPermissions("tcwPointTransfer:flow")
	@GetMapping("/toFlow")
	public String toFlow(Model model, HttpServletRequest request, HttpServletResponse response,
			String bid){
		if (bid == null || bid.length() == 0) {
			return W.error(model, "单号不能为空");
		}
		
		TcwPointTransfer entity = new TcwPointTransfer().setBid(bid).queryFirst();
		
		try {
			return commonApiService.toEdit(model, entity.getId(), new TcwPointTransfer(), ApiInterTcwPointTransferController.MENU_ID, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, "数据异常，请联系客服处理");
		}
	}
}